/******************************************************************************************************
 * Author		:	Chester Ragel
 * Date			:	01 - March - 2007
 * Description	:	Helper class to do registration of context menu
 * 
 * ****************************************************************************************************/

/*
 *  Context Menu Extention is the legal property of its developer
 *  Chester Ragel <chesterr@gmail.com> - Developer and Maintainer
 *	Sourceforge ID : chesterr
 *	Yahoo ID : chesterr1979 
 *	MSN : chesterr79@hotmail.com
 *	Gmail: chesterr@gmail.com
 *
 * If you want more information, found any bugs or have any doubts you 
 * can mail me or contact me through my yahoo id.
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#region Namespace

using System;
using Microsoft.Win32;

#endregion

namespace Keyrox.Shell {
    /// <summary>
    /// Helper class to do registration of context menu
    /// </summary>
    public class RegisterContextMenu {

        #region Methods

        /// <summary>
        /// Register a perticular type with its guid
        /// </summary>
        /// <param name="type"></param>
        /// <param name="classGuid"></param>
        public static void Register(string type, Guid classGuid) {
            try {
                string strGuid = string.Format("{{{0}}}", classGuid.ToString());
                string strReg = string.Format(@"{0}\shellex\ContextMenuHandlers\{1}", type, strGuid);
                using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(strReg)) {
                    key.SetValue("", strGuid);
                }
            }
            catch {
            }
        }

        /// <summary>
        /// unRegister a perticular type with its guid
        /// </summary>
        /// <param name="type"></param>
        /// <param name="classGuid"></param>
        public static void Unregister(string type, Guid classGuid) {
            try {
                string strGuid = string.Format("{{{0}}}", classGuid.ToString());
                string strReg = string.Format(@"{0}\shellex\ContextMenuHandlers", type);
                using (RegistryKey key = Registry.ClassesRoot.OpenSubKey(strReg, true)) {
                    key.DeleteSubKey(strGuid, false);
                }
            }
            catch {
            }
        }

        #endregion

    }
}